﻿using Microsoft.AspNetCore.Mvc;
using seejee_Backendium.Core.Interfaces;
using seejee_Backendium.Core.Models;
using seejee_Backendium.Data.Services;

namespace seejee_Backendium.WEB.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class AccountSetListController : ControllerBase
    {
        private readonly ILogger<AccountSetListController> _logger;
        private readonly IAccountSetListService _accountSetListService;
        // 构造函数修复：正确赋值_logger
        public AccountSetListController(ILogger<AccountSetListController> logger, IAccountSetListService accountSetListService)
        {
            _logger = logger;
            _accountSetListService = accountSetListService;
        }

        #region 1. 查询操作
        /// <summary>
        /// 获取所有数据源记录
        /// </summary>
        /// <returns>所有记录列表</returns>
        [HttpGet("all")] // 路由：api/AccountSetList/all
        public async Task<ActionResult<IEnumerable<AccountSetList>>> GetAllAccList()
        {
            try
            {
                var result = await _accountSetListService.GetAllAsync();
                return Ok(result); // 无论空/非空，均返回200+数据（空集合也比404更合理）
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "获取所有数据源记录失败");
                return StatusCode(500, "服务器内部错误：获取数据失败");
            }
        }
    }
    #endregion
}